
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>Zookeeper是如何保证高可用性的？ - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>Zookeeper是如何保证高可用性的？ - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">架构</div>
          <div class="card-question">在 Zookeeper 集群中，领导者（Leader）和跟随者（Follower）的角色和职责有何不同？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">架构</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Zookeeper 集群中的节点分为领导者和跟随者。只有领导者节点负责处理写请求，并将修改同步到所有跟随者节点；而跟随者节点则负责处理读请求和向领导者同步数据。</div>
          </div>
          <div class="card-source">来源: 1. Zookeeper 的集群架构</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Zookeeper 使用什么协议来保证数据一致性和高可用性？该协议如何应对领导者节点故障？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Zookeeper 使用 ZAB（Zookeeper Atomic Broadcast）协议来保证数据的复制和一致性。该协议包含一个选举机制，当领导者节点失败时，能够迅速选举出新的领导者，从而保证系统的高可用性。</div>
          </div>
          <div class="card-source">来源: 1. Zookeeper 的集群架构</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">为什么建议将 Zookeeper 集群的节点数量配置为奇数？保证高可用性所需的最小节点数是多少？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">配置奇数个节点是为了确保在发生网络分区或节点故障时，集群仍然可以通过多数节点来进行决策。为了保证高可用性，集群至少需要 3 个节点。</div>
          </div>
          <div class="card-source">来源: 2.1. 配置足够数量的节点</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">Zookeeper 中 `dataDir` 和 `dataLogDir` 这两个配置项分别用于什么目的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">`dataDir` 用于指定数据存储目录，将数据持久化到磁盘以防止丢失。`dataLogDir` 用于指定事务日志目录，存储事务日志，以便在系统恢复时重放未持久化的数据更改。</div>
          </div>
          <div class="card-source">来源: 2.3. 配置持久化</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">什么是 Zookeeper 的快照（snapshot）？哪个配置参数可以控制其生成频率？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">快照是 Zookeeper 数据的完整副本，主要用于在节点重启时进行数据恢复。可以通过配置 `snapCount` 参数来控制生成快照的频率，以减少系统负载并提高恢复速度。</div>
          </div>
          <div class="card-source">来源: 2.4. 配置异步快照</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">配置</div>
          <div class="card-question">配置 Zookeeper 的会话超时时间（sessionTimeout）时需要考虑什么权衡？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">配置</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在配置 `sessionTimeout` 时需要权衡响应速度和误判风险。较短的超时时间可以更快地检测到节点故障，从而提高响应速度，但同时也可能增加因网络波动等原因导致误判的风险。</div>
          </div>
          <div class="card-source">来源: 2.2. 配置适当的超时时间</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
